package com.finalist.dao.impl;


import javax.persistence.FlushModeType;

import org.springframework.stereotype.Repository;

import com.finalist.dao.DestinationDao;
import com.finalist.entity.Destination;

@Repository("destinationDaoImpl")
public class DestinationDaoImpl extends BaseDaoImpl<Destination, Long> implements DestinationDao{

	  @Override
	    public boolean nameExists(String name)
	    {
		  if (name == null)
	        {
	            return false;
	        }
		  	String jpql = "select count(*) from Destination de where lower(de.name) = lower(:name)";
			Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT).setParameter("name", name).getSingleResult();
			return count > 0;
	    }
}
